package com.zs.studentmanager.controller;

import com.zs.studentmanager.common.ResponseCodeEnum;
import com.zs.studentmanager.common.Result;
import com.zs.studentmanager.entity.vo.HomeVo;
import com.zs.studentmanager.service.CourseService;
import com.zs.studentmanager.service.GradeClassService;
import com.zs.studentmanager.service.StudentService;
import com.zs.studentmanager.service.TeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 周小白
 * @date: 2024-01-26 18:23
 **/
@RestController
@RequestMapping("/home")
@Tag(name = "首页接口", description = "首页相关接口")
public class HomeController {

    private final StudentService studentService;

    private final TeacherService teacherService;

    private final CourseService courseService;

    private final GradeClassService gradeClassService;


    public HomeController(StudentService studentService, TeacherService teacherService, CourseService courseService, GradeClassService gradeClassService) {
        this.studentService = studentService;
        this.teacherService = teacherService;
        this.courseService = courseService;
        this.gradeClassService = gradeClassService;
    }



    /**
     * 获取首页信息
     * @return
     */
    @GetMapping
    @Operation(summary = "获取首页信息")
    public Result getHomeInfo(){
        long studentNum = studentService.count();
        long teacherNum = teacherService.count();
        long courseNum = courseService.count();
        long classNum = gradeClassService.count();

        if (studentNum == 0 && teacherNum == 0 && courseNum == 0 && classNum == 0) {
            return Result.fail(ResponseCodeEnum.SYSTEM_ERROR);
        }

        HomeVo homeVo = new HomeVo();
        homeVo.setStudentNum(studentNum);
        homeVo.setTeacherNum(teacherNum);
        homeVo.setCourseNum(courseNum);
        homeVo.setClassNum(classNum);

        return Result.success(homeVo);
    }
}
